package org.pine.dao;

import org.pine.model.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.List;

/**
 * 实现自定义路径请求 @RepositoryRestResource注解实现
 * path 表示将请求路径中的books都修改为bs
 * collectionResourceRel 属性将返回JSON集合中的book集合中的key修改为bs
 * itemResourceRel 属性将返回的JSON集合中的单个book的key修改为b
 * @author liucs
 */
@CrossOrigin
@RepositoryRestResource(path = "bs",collectionResourceRel = "bs",itemResourceRel = "b")
public interface BookRepository extends JpaRepository<Book, Integer> {
    /**
     * exported = false 该接口方法不暴露
     * @ param integer
     */
    @Override
    @RestResource(exported = false)
    void deleteById(Integer integer);

    /**
     * 自定义查询方法
     * @ param author
     * @ return
     */
    @RestResource(path = "author",rel = "author")
    List<Book> findByAuthorContains(@Param("author") String author);

    @RestResource(path = "name",rel = "name")
    Book findByNameEquals(@Param("name") String name);
}
